package com.example.demo;

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author corgi
 * @since 2022-09-04 21:28
 */
@Component
public class MyKeyGen implements KeyGenerator {
	/**
	 * Generate a key for the given method and its parameters.
	 *
	 * @param target the target instance
	 * @param method the method being called
	 * @param params the method parameters (with any var-args expanded)
	 * @return a generated key
	 */
	@Override
	public Object generate(Object target, Method method, Object... params) {
		// 使用方法签名作为 cache key
		return method.getName() + ":" + Arrays.toString(params);
	}
}
